﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace MSN
{
    abstract class AppData
    {
        private Dictionary<string, string> propertyDict = null;
        protected XmlDocument xmlDoc = null;
        private string xmlFile = string.Empty;
        

        public AppData(string xmlFile) 
        {
            this.xmlFile = xmlFile;
            if(!System.IO.File.Exists(xmlFile))
            {
                throw new Exception("The XML file not exists");
            }
            this.LoadXml();
        }
        
        public Dictionary<string, string> PropertyDict
        {
            get 
            {
                if (this.propertyDict == null)
                {
                    this.propertyDict = new Dictionary<string, string>();
                }
                return this.propertyDict;
            }
        }

        public abstract void InitData(string xPath);

        private void LoadXml() 
        {
            xmlDoc = new XmlDocument();
            try
            {
                xmlDoc.Load(xmlFile);
            }
            catch (Exception err) 
            {
                throw new Exception(string.Format("Failed to load the XML for: {0}", err.Message));
            }
        }
    }
}
